package com.jakewharton.rxbinding4.component;

import static com.jakewharton.rxbinding4.internal.Preconditions.checkNotNull;

import io.reactivex.rxjava3.annotations.CheckReturnValue;
import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.functions.Consumer;
import ohos.agp.components.ProgressBar;

/**
 * Rx progress bar
 */
public final class RxProgressBar {
    /**
     * An action which sets whether {@code view} is indeterminate.
     * <p>
     * <em>Warning:</em> The created observable keeps a strong reference to {@code view}. Unsubscribe
     * to free this reference.
     *
     * @param view view
     * @return the consumer
     */
    @CheckReturnValue
    @NonNull
    public static Consumer<? super Boolean> indeterminate(@NonNull ProgressBar view) {
        checkNotNull(view, "view == null");
        return view::setIndeterminate;
    }

    /**
     * An action which sets the max value of {@code view}.
     * <p>
     * <em>Warning:</em> The created observable keeps a strong reference to {@code view}. Unsubscribe
     * to free this reference.
     *
     * @param view view
     * @return the consumer
     */
    @CheckReturnValue
    @NonNull
    public static Consumer<? super Integer> max(@NonNull ProgressBar view) {
        checkNotNull(view, "view == null");
        return view::setMaxValue;
    }

    /**
     * An action which sets the progress value of {@code view}.
     * <p>
     * <em>Warning:</em> The created observable keeps a strong reference to {@code view}. Unsubscribe
     * to free this reference.
     *
     * @param view view
     * @return the consumer
     */
    @CheckReturnValue
    @NonNull
    public static Consumer<? super Integer> progress(@NonNull ProgressBar view) {
        checkNotNull(view, "view == null");
        return view::setProgressValue;
    }

    /**
     * An action which sets the secondary progress value of {@code view}.
     * <p>
     * <em>Warning:</em> The created observable keeps a strong reference to {@code view}. Unsubscribe
     * to free this reference.
     *
     * @param view view
     * @return the consumer
     */
    @CheckReturnValue
    @NonNull
    public static Consumer<? super Integer> secondaryProgress(@NonNull ProgressBar view) {
        checkNotNull(view, "view == null");
        return view::setViceProgress;
    }

    private RxProgressBar() {
        throw new AssertionError("No instances.");
    }
}
